<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【请填写功能名称】列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>培养计划：</p>
                                <input type="text" name="planName"/>
                            </li>
                            <li>
                                <p>专业：</p>
                                <input type="text" name="profession"/>
                            </li>

                            <li>
                                <p>版本：</p>
                                <input type="text" name="version"/>
                            </li>
                            <li class="select-time">
                                <p>生效时间：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="beginEffectiveTime"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endEffectiveTime"/>
                            </li>
                            <li>
                                <p>总分数：</p>
                                <input type="text" name="totalScores"/>
                            </li>
                            <li>
                                <p>总学时：</p>
                                <input type="text" name="totalTime"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.modal.openTab('添加培养计划',ctx+'website/trainplan/add')" shiro:hasPermission="website:trainplan:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="website:trainplan:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="website:trainplan:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="website:trainplan:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var fabu = [[${@permission.hasPermi('website:trainplan:fabu')}]];
        var quxiaofabu = [[${@permission.hasPermi('website:trainplan:quxiaofabu')}]];
        var editFlag = [[${@permission.hasPermi('website:trainplan:edit')}]];
        var removeFlag = [[${@permission.hasPermi('website:trainplan:remove')}]];
        var prefix = ctx + "website/trainplan";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "培养计划",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : '序号',
                    visible: true,
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field : 'planName', 
                    title : '培养计划名称'
                },
                {
                    field : 'profession', 
                    title : '专业'
                },
                {
                    field : 'version', 
                    title : '版本'
                },
                {
                    field : 'effectiveTime', 
                    title : '生效时间'
                },
                {
                    field : 'totalScores', 
                    title : '总分数'
                },
                {
                    field : 'totalTime', 
                    title : '总学时'
                },
                {
                    filed : 'isFabu',
                    title : '发布',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.isFabu == 0 || row.isFabu==null) {
                            actions.push('<a class="btn btn-success btn-xs'+fabu+'" href="javascript:void(0)" onclick=" fabuFlag(\'' + row.id + '\')"><i class="fa fa-edit"></i>发布</a> ');
                        } else if(row.isFabu == 1){
                            actions.push('<a class="btn btn-success btn-xs'+quxiaofabu+'" href="javascript:void(0)" onclick=" quxiaofabuFlag(\'' + row.id + '\')"><i class="fa fa-edit"></i>取消发布</a> ');
                        }
                        return actions.join('');
                    }

                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function edit(val) {
            //console.log(val);
            $.modal.openTab('修改培养计划',ctx+'website/trainplan/edit/'+val);
        }

        function fabuFlag(val) {
            debugger;
            // var data1 = {
            //     id:id,
            //     name:name,
            // };
            $.modal.confirm("确认要发布吗?", function () {
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    url: prefix + "/fabu",
                    data: {
                        id: val,
                    },
                    cache: false,
                    async: true,
                    success: function (data) {
                        $.modal.alertSuccess("发布成功");
                        $.table.refresh();

                    }

                });
            });
        }
        function quxiaofabuFlag(val) {
            debugger;
            /* var loginName = $.table.selectColumns("loginName");
             alert(loginName);
             return false;*/
            $.modal.confirm("确认要取消发布吗?", function () {
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    url: prefix + "/quxiaofabu",
                    data: {
                        id: val,
                    },
                    cache: false,
                    async: true,
                    success: function (data) {
                        $.modal.alertSuccess("取消成功");
                        $.table.refresh();
                    }
                });
            });
        }

    </script>
</body>
</html>